<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Extract entry from the archive</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="class.rarentry.html">« RarEntry</a></li>
      <li style="float: right;"><a href="rarentry.getattr.html">RarEntry::getAttr »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="class.rarentry.html">RarEntry</a></li>
    <li>Extract entry from the archive</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="rarentry.extract" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">RarEntry::extract</h1>
  <p class="verinfo">(PECL rar &gt;= 0.1)</p><p class="refpurpose"><span class="refname">RarEntry::extract</span> &mdash; <span class="dc-title">Extract entry from the archive</span></p>

 </div>
 
 <div class="refsect1 description" id="refsect1-rarentry.extract-description">
  <h3 class="title">说明</h3>
   <div class="methodsynopsis dc-description">
    <span class="modifier">public</span> <span class="methodname"><strong>RarEntry::extract</strong></span>(<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type">string</span> <code class="parameter">$dir</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type">string</span> <code class="parameter">$filepath</code><span class="initializer"> = &quot;&quot;</span></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type">string</span> <code class="parameter">$password</code><span class="initializer"> = NULL</span></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type">bool</span> <code class="parameter">$extended_data</code><span class="initializer"> = <strong><code>false</code></strong></span></span><br>): <span class="type">bool</span></div>

  <p class="para rdfs-comment">
   <span class="methodname"><strong>RarEntry::extract()</strong></span> extracts the entry&#039;s data.
   It will create new file in the specified
   <code class="parameter">dir</code> with the name identical to the entry&#039;s name,
   unless the second argument is specified. See below for more information.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-rarentry.extract-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>
    
     <dt>
<code class="parameter">dir</code></dt>

     <dd>

      <p class="para">
       Path to the directory where files should be extracted. This parameter is
       considered if and only if <code class="parameter">filepath</code> is not. If both
       parameters are empty an extraction to the current directory will be
       attempted.
      </p>
     </dd>

    
    
    
     <dt>
<code class="parameter">filepath</code></dt>

     <dd>

      <p class="para">
       Path (relative or absolute) containing the directory and filename of the
       extracted file. This parameter overrides both the parameter
       <code class="parameter">dir</code> and the original file name.
      </p>
     </dd>

    
    
    
     <dt>
<code class="parameter">password</code></dt>

     <dd>

      <p class="para">
       The password used to encrypt this entry. If the entry is not encrypted, this value will not be used and can
       be omitted. If this parameter is omitted and the entry is encrypted, the password given to
       <span class="function"><a href="rararchive.open.html" class="function">rar_open()</a></span>, if any, will be used. If a wrong password is given, either explicitly
       or implicitly via <span class="function"><a href="rararchive.open.html" class="function">rar_open()</a></span>, CRC checking will fail and this method will fail and return <strong><code>false</code></strong>.
       If no password is given and one is required, this method will fail and return <strong><code>false</code></strong>.
       You can check whether an entry is encrypted with <span class="methodname"><a href="rarentry.isencrypted.html" class="methodname">RarEntry::isEncrypted()</a></span>.
      </p>
     </dd>

    

   
    <dt>
<code class="parameter">extended_data</code></dt>

    <dd>

     <p class="para">
       If <strong><code>true</code></strong>, extended information such as NTFS ACLs and Unix owner information will be set in the extract
       files, as long as it&#039;s present in the archive.
     </p>
    </dd>

   
   </dl>

  </p>
  <div class="warning"><strong class="warning">警告</strong>
      <p class="para">Prior to version 2.0.0, this function would not handle relative
      paths correctly. Use <span class="function"><a href="function.realpath.html" class="function">realpath()</a></span> as a workaround.</p>
  </div>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-rarentry.extract-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   成功时返回 <strong><code>true</code></strong>， 或者在失败时返回 <strong><code>false</code></strong>。
  </p>
 </div>


 <div class="refsect1 changelog" id="refsect1-rarentry.extract-changelog">
  <h3 class="title">更新日志</h3>
  <p class="para">
   <table class="doctable informaltable">
    
     <thead>
      <tr>
       <th>版本</th>
       <th>说明</th>
      </tr>

     </thead>

     <tbody class="tbody">
      <tr>
       <td>PECL rar 3.0.0</td>
       <td>
        <code class="parameter">extended_data</code> was added.
       </td>
      </tr>

      <tr>
       <td>PECL rar 3.0.0</td>
       <td>
        Support for RAR archives with repeated entry names is no longer defective.
       </td>
      </tr>

     </tbody>
    
   </table>

  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-rarentry.extract-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-813">
    <p><strong>示例 #1 <span class="methodname"><strong>RarEntry::extract()</strong></span> example</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /><br />$rar_file&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">rar_open</span><span style="color: #007700">(</span><span style="color: #DD0000">'example.rar'</span><span style="color: #007700">)&nbsp;or&nbsp;die(</span><span style="color: #DD0000">"Failed&nbsp;to&nbsp;open&nbsp;Rar&nbsp;archive"</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$entry&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">rar_entry_get</span><span style="color: #007700">(</span><span style="color: #0000BB">$rar_file</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'Dir/file.txt'</span><span style="color: #007700">)&nbsp;or&nbsp;die(</span><span style="color: #DD0000">"Failed&nbsp;to&nbsp;find&nbsp;such&nbsp;entry"</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$entry</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">extract</span><span style="color: #007700">(</span><span style="color: #DD0000">'/dir/to'</span><span style="color: #007700">);&nbsp;</span><span style="color: #FF8000">//&nbsp;create&nbsp;/dir/to/Dir/file.txt<br /></span><span style="color: #0000BB">$entry</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">extract</span><span style="color: #007700">(</span><span style="color: #0000BB">false</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'/dir/to/new_name.txt'</span><span style="color: #007700">);&nbsp;</span><span style="color: #FF8000">//&nbsp;create&nbsp;/dir/to/new_name.txt<br /><br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

   </div>
   <div class="example" id="example-814">
    <p><strong>示例 #2 How to extract all files in archive: </strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /><br /></span><span style="color: #FF8000">/*&nbsp;example&nbsp;by&nbsp;Erik&nbsp;Jenssen&nbsp;aka&nbsp;erix&nbsp;*/<br /><br /></span><span style="color: #0000BB">$filename&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">"foobar.rar"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$filepath&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">"/home/foo/bar/"</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">$rar_file&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">rar_open</span><span style="color: #007700">(</span><span style="color: #0000BB">$filepath</span><span style="color: #007700">.</span><span style="color: #0000BB">$filename</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$list&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">rar_list</span><span style="color: #007700">(</span><span style="color: #0000BB">$rar_file</span><span style="color: #007700">);<br />foreach(</span><span style="color: #0000BB">$list&nbsp;</span><span style="color: #007700">as&nbsp;</span><span style="color: #0000BB">$file</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$entry&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">rar_entry_get</span><span style="color: #007700">(</span><span style="color: #0000BB">$rar_file</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$file</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$entry</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">extract</span><span style="color: #007700">(</span><span style="color: #DD0000">"."</span><span style="color: #007700">);&nbsp;</span><span style="color: #FF8000">//&nbsp;extract&nbsp;to&nbsp;the&nbsp;current&nbsp;dir<br /></span><span style="color: #007700">}<br /></span><span style="color: #0000BB">rar_close</span><span style="color: #007700">(</span><span style="color: #0000BB">$rar_file</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

   </div>
  </p>
 </div>

 
 <div class="refsect1 seealso" id="refsect1-rarentry.extract-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="methodname"><a href="rarentry.getstream.html" class="methodname" rel="rdfs-seeAlso">RarEntry::getStream()</a> - Get file handler for entry</span></li>
    <li class="member"><a href="wrappers.rar.html" class="link"><code class="literal">rar://</code> wrapper</a></li>
   </ul>
  </p>
 </div>


</div></div></div></body></html>